tests: Support TEST_SKIP_CLEANUP=err
authorColin Walters <walters@verbum.org>
Fri, 18 Nov 2016 20:07:52 +0000 (15:07 -0500)
committerAtomic Bot <atomic-devel@projectatomic.io>
Mon, 21 Nov 2016 16:11:55 +0000 (16:11 +0000)
I find myself often wanting to debug interactively failing tests.
This makes it more convenient to keep around the temporary directories
just for those tests, rather than accumulating tons of tempdirs from
the successful tests as well.

Closes: #588
Approved by: jlebon

buildutil/tap-test

index 6b2eb5c1bf7c96a35355bda9ba9c0d24e573090e..c8da31e7418665d0642c67e9d7bcce6602d9eb34 100755 (executable)
@@ -11,13 +11,24 @@ bn=$(basename $1)
 tempdir=$(mktemp -d /var/tmp/tap-test.XXXXXX)
 touch ${tempdir}/.testtmp
 function cleanup () {
-    if test -n "${TEST_SKIP_CLEANUP:-}"; then
-       echo "Skipping cleanup of ${tempdir}"
-    else if test -f ${tempdir}/.testtmp; then
+    if test -f ${tempdir}/.testtmp; then
        rm "${tempdir}" -rf
     fi
-    fi
 }
-trap cleanup EXIT
+function skip_cleanup() {
+    echo "Skipping cleanup of ${tempdir}"
+}
 cd ${tempdir}
 ${srcd}/${bn} -k --tap
+rc=$?
+case "${TEST_SKIP_CLEANUP:-}" in
+    no|"") cleanup ;;
+    err)
+       if test $rc != 0; then
+           skip_cleanup
+       else
+           cleanup
+       fi ;;
+    *) skip_cleanup  ;;
+esac
+exit $rc